package tech.veedo.munchkin.controllers.backend;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import tech.veedo.munchkin.beans.backend.Auditor;
import tech.veedo.munchkin.constants.Operation;
import tech.veedo.munchkin.services.backend.AuditorService;
import tech.veedo.munchkin.verifications.backend.AuditorVerify;

import java.util.List;

@RestController
@RequestMapping("/munc/auditor")
@Api(tags = "1-后台-4-审核人员接口集合")
public class AuditorController {

    private final AuditorService auditorService;

    private final AuditorVerify auditorVerify;

    public AuditorController(AuditorService auditorService, AuditorVerify auditorVerify) {
        this.auditorService = auditorService;
        this.auditorVerify = auditorVerify;
    }

    @PostMapping("/save")
    @ApiOperation("保存审核人员")
    public boolean save(Auditor auditor) {
        auditorVerify.verify(Operation.ADD, auditor);
        return auditorService.saveAuditor(auditor);
    }

    @PostMapping("/update")
    @ApiOperation(("更新审核人员"))
    public boolean update(Auditor auditor) {
        auditorVerify.verify(Operation.UPDATE, auditor);
        return auditorService.updateAuditor(auditor);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除审核人员")
    public boolean delete(@PathVariable Long id) {
        return auditorService.deleteAuditor(id);
    }

    @GetMapping("/n/{id}/list")
    @ApiOperation("获取当前节点的审核人员名单")
    public List<Auditor> getAuditorsByNode(@PathVariable Long id) {
        return auditorService.getAuditorsByNode(id);
    }

}
